#include "stdafx.h"

#include "RObject.h"

RObject::RObject(const GLuint& capacity, shared_ptr<Material> mat, const GLenum& primitive_type):
	capacity(capacity),
	primitive_count(0),
	primitive_type(primitive_type),
	mat(mat)
{
	vertices = new GLfloat[capacity];
}

RObject::~RObject(){
	delete[] vertices;
	mat = 0;//FIXME: will this delete the pointer
}

void RObject::initialize(){
	mat->initialize_once();
}

void RObject::render(){
	mat->initialize_specific(vertices);
	switch (primitive_type){
	case GL_LINES:
		glDrawArrays(primitive_type, 0, primitive_count*2);
		//glDrawArrays(primitive_type, 0, primitive_count);
		CHECKGL;
		break;
	case GL_TRIANGLES:
		glDrawArrays(primitive_type, 0, primitive_count*3);
		CHECKGL;
		break;
	default:
		LOGE("not yet implemented");
	}
}
